/*
 * @lc app=leetcode.cn id=121 lang=javascript
 *
 * [121] 买卖股票的最佳时机
 */

// @lc code=start
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  const n = prices.length;
  let min = prices[0];
  let maxres = 0;
  for (let i = 1; i < n; i++) {
    min = Math.min(prices[i], min);
    maxres = Math.max(prices[i] - min, maxres);
  }
  return maxres;
};
// @lc code=end
